import useDictStore from '@/store/modules/dict'

/**
 * 获取字典数据
 */
export function useDict(...args) {
  const res = ref({})
  return (() => {
    args.forEach((dictType) => {
      res.value[dictType] = []
      const dicts = useDictStore().getDict(dictType)
      if (dicts) {
        res.value[dictType] = dicts
      }
    })
    return toRefs(res.value)
  })()
}

export function translateDict(dictType) {
  const data = useDict(dictType)
  const dictData = data[dictType].value
  return (row, column, cellValue) => {
    for (let item of dictData) {
      if (item.dictCode === cellValue) {
        return item.dictNameCn
      }
    }
    return cellValue
  }
}
